package com.flash.mapper;

import com.flash.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {
    /**
     * 动态条件查询（根据传进来的是菜品id还是套餐id进行查询）
     * @param shoppingCart
     * @return
     */
    List<ShoppingCart> list(ShoppingCart shoppingCart);

    /**
     * 如果存在那么把这个菜品或者套餐的数量+1
     * @param shoppingCart
     */
    void addIfExtist(ShoppingCart shoppingCart);

    /**
     * 如果购物车中没有此条数据那么便将此条数据插入
     * @param shoppingCart
     */
    @Insert("insert into " +
            "flash_delivery.shopping_cart" +
            " (name, image, user_id, dish_id, setmeal_id, dish_flavor, number, amount, create_time) values " +
            "(#{name},#{image} ,#{userId} ,#{dishId} ,#{setmealId} ,#{dishFlavor} ,#{number} ,#{amount} ,#{createTime} )")
    void insert(ShoppingCart shoppingCart);

    @Select("select * from flash_delivery.shopping_cart where user_id = #{userId} ")
    List<ShoppingCart> listAll(Long userId);
    @Delete("delete  from flash_delivery.shopping_cart where user_id = #{userId}")
    void cleanChart(Long userId);
    void sub(ShoppingCart shoppingCart);
    @Delete("delete from flash_delivery.shopping_cart where id = #{id} ")
    void delete(ShoppingCart cart);

    void insertBatch(List<ShoppingCart> shoppingCarts);
}
